<% layout('/layouts/default.html', {title: '活动管理', libs: ['validate','fileupload','ueditor','dataGrid']}){ %>
<div class="main-content">
	<div class="box box-main">
		<div class="box-header with-border">
			<div class="box-title">
				<i class="fa fa-list-alt"></i> ${text(wxActivity.isNewRecord ? '新增wx_activity' : '编辑活动')}
			</div>
			<div class="box-tools pull-right">
				<button type="button" class="btn btn-box-tool" data-widget="collapse"><i class="fa fa-minus"></i></button>
			</div>
		</div>
		<#form:form id="inputForm" model="${wxActivity}" action="${ctx}/wx/wxActivity/save" method="post" class="form-horizontal">
			<div class="box-body">
				<div class="form-unit">${text('基本信息')}</div>
				<#form:hidden path="id"/>
				<div class="row">
					<!--<div class="col-xs-6">-->
						<!--<div class="form-group">-->
							<!--<label class="control-label col-sm-4" title="">-->
								<!--<span class="required hide">*</span> ${text('活动名称')}：<i class="fa icon-question hide"></i></label>-->
							<!--<div class="col-sm-8">-->
								<!--<#form:input path="name" maxlength="200" class="form-control"/>-->
							<!--</div>-->
						<!--</div>-->
					<!--</div>-->
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required ">*</span> ${text('活动标题')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input id="title" path="title" maxlength="200" class="form-control required"/>
							</div>
						</div>
					</div>
				</div>
				<div class="row">
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required ">*</span> ${text('活动开始时间')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="beginTime" readonly="true" maxlength="20" class="form-control Wdate required date"
									dataFormat="datetime" onclick="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm',isShowClear:false});"/>
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required ">*</span> ${text('活动结束时间')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="endTime" readonly="true" maxlength="20" class="form-control Wdate required date"
									dataFormat="datetime" onclick="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm',isShowClear:false});"/>
							</div>
						</div>
					</div>
				</div>
				<div class="row">
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required ">*</span> ${text('核销开始时间')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="afterBeginTime" readonly="true" maxlength="20" class="form-control Wdate required date"
								dataFormat="datetime" onclick="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm',isShowClear:false});"/>
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required ">*</span> ${text('核销结束时间')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="afterEndTime" readonly="true" maxlength="20" class="form-control Wdate required date"
								dataFormat="datetime" onclick="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm',isShowClear:false});"/>
							</div>
						</div>
					</div>
				</div>
				<div class="row">
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required hide">*</span> ${text('客服电话')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="phone" maxlength="200" class="form-control mobile"/>
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required hide">*</span> ${text('参与人数')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="num" maxlength="11" class="form-control digits"/>
							</div>
						</div>
					</div>
				</div>

				<div class="row">
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required hide">*</span> ${text('活动价格')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="price" maxlength="200" class="form-control number"/>
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required hide">*</span> ${text('限购一次')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:select path="oneTime" dictType="activity_one_time"  class="form-control" />
							</div>
						</div>
					</div>
				</div>

				<div class="row">
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required hide">*</span> ${text('规则说明')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<div id="editor" style="height:324px;width:560px;" >
								</div>
							</div>
						</div>
					</div>
				</div>

				<div class="row" style="display: none;">
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required hide">*</span> ${text('规则说明text')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
									<#form:textarea id="ruleText" path="rule" rows="10" maxlength="1000"
								class="form-control" style="width: 500px; height: 300px"/>
							</div>
						</div>
					</div>
				</div>

				<div class="row">
					<div class="col-xs-12">
						<div class="form-group">
							<label class="control-label col-sm-2" title="">
								<span class="required hide">*</span> ${text('入群二维码')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-4">
								<#form:fileupload id="upload2" bizKey="1" bizType="1"
								uploadType="image" readonly="false" maxUploadNum="1" returnPath="true" filePathInputId="groupPic"/>
								<#form:hidden path="groupPic" name="groupPic" id="groupPic" />

							</div>

							<div>
								已上传图片：<img src="${wxActivity.groupPic}" width="80px" height="80px">
							</div>

						</div>
					</div>
				</div>

				<div class="form-unit">${text('返佣设置')}</div>
				<div class="row">
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required hide">*</span> ${text('返佣设置')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="disValue" rows="5" maxlength="500" class="form-control"/>
							</div>
						</div>
					</div>
				</div>

				<div class="form-unit">${text('页面装修')}</div>
				<div class="row">
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required hide">*</span> ${text('主题一')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<div>
									<img  src="/theme1.jpg" width="800" height="200">
									<input type="radio" value="1" name="theme" id="theme1">选择
								</div>
							</div>
						</div>
					</div>
				</div>
				<div class="row">
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required hide">*</span> ${text('主题二')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<div>
									<img  src="/theme2.jpg" width="800px" height="200px">
									<input type="radio" value="2" name="theme" id="theme2">选择
								</div>
							</div>
						</div>
					</div>
				</div>
				<div class="row">
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required hide">*</span> ${text('主题三')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<div>
									<img  src="/theme3.jpg" width="800px" height="200px">
									<input type="radio" value="3" name="theme" id="theme3">选择
								</div>
							</div>
						</div>
					</div>
				</div>
				<div class="row">
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required hide">*</span> ${text('主题四')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<div>
									<img  src="/theme4.jpg" width="800px" height="200px">
									<input type="radio" value="4" name="theme" id="theme4">选择
								</div>
							</div>
						</div>
					</div>
				</div>
				<div class="row">
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required hide">*</span> ${text('主题五')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<div>
									<img  src="/theme5.jpg" width="800px" height="200px">
									<input type="radio" value="5" name="theme" id="theme5">选择
								</div>
							</div>
						</div>
					</div>
				</div>
				<div class="row">
					<div class="col-xs-12">
						<div class="form-group">
							<label class="control-label col-sm-2" title=""><span class="required hide">*</span> ${text('活动海报')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-4">
								<#form:fileupload id="uploadBannerPic" bizKey="1" bizType="1"
								uploadType="image" readonly="false" maxUploadNum="1" returnPath="true" filePathInputId="bannerPic"/>
								<#form:hidden path="bannerPic" name="bannerPic" id="bannerPic" />

							</div>
							<div>
								已上传图片：<img src="${wxActivity.bannerPic}" width="80px" height="80px">
							</div>
						</div>
					</div>
				</div>
				<div class="row">
					<div class="col-xs-12">
						<div class="form-group">
							<label class="control-label col-sm-2" title=""><span class="required hide">*</span> ${text('我的邀请banner图(750×1206)')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-4">
								<#form:fileupload id="uploadinviteBannerPicPic" bizKey="1" bizType="1"
										uploadType="image" readonly="false" maxUploadNum="1" returnPath="true" filePathInputId="inviteBannerPic"/>
								<#form:hidden path="inviteBannerPic" name="inviteBannerPic" id="inviteBannerPic" />

							</div>
							<div>
								已上传图片：<img src="${wxActivity.inviteBannerPic}" width="80px" height="80px">
							</div>
						</div>
					</div>
				</div>
				<div class="row" style="display: none">
					<div class="col-xs-12">
						<div class="form-group">
							<label class="control-label col-sm-2" title=""><span class="required hide">*</span> ${text('邀请图自定义位置')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-4">
								<span class="required">* </span><span>相对于"我的邀请banner图"左上角的X/Y正整数坐标,用逗号隔开例如:80,200</span><br>
								二维码坐标位置：<#form:input path="qrIndex" rows="5" maxlength="500" class="form-control"/>
								头像坐标位置：<#form:input path="headImgIndex" rows="5" maxlength="500" class="form-control"/>
								昵称坐标位置：<#form:input path="userNameIndex" rows="5" maxlength="500" class="form-control"/>
							</div>
						</div>
					</div>
				</div>
				<div class="row">
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required hide">*</span> ${text('我为XXX代言描述')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="remarks" rows="5" maxlength="500" class="form-control"/>
							</div>
						</div>
					</div>
				</div>
				<div class="row">
					<div class="col-xs-12">
						<div class="form-group">
							<label class="control-label col-sm-2" title="">
								<span class="required hide">*</span> ${text('主动刷新用户邀请图片')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-4">
								<#form:select path="refreshInviteImg" dictType="refresh_invite_img"  class="form-control" />
							</div>
						</div>
					</div>
				</div>
				<div class="row">
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required hide">*</span> ${text('背景音乐')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<!--<video controls="controls" preload="auto">-->
									<!--<source src="${wxActivity.bgm}" type="video/ogg" />-->
								<!--</video>-->

								<!--<audio id="bgMusic" src="${wxActivity.bgm}" autoplay preload loop="loop"></audio>-->
								<#form:fileupload id="uploadFileBgm" bizKey="}" bizType="testData_file"
										uploadType="all" class="" readonly="false" maxUploadNum="1" returnPath="true" filePathInputId="bgm"/>
								<#form:hidden path="bgm" name="bgm" id="bgm" />
								<div>
									已上传音乐：<span>${wxActivity.bgm}</span>
								</div>
							</div>
						</div>
					</div>
				</div>


				<div class="form-unit">${text('分享设置')}</div>
				<div class="row">
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required hide">*</span> ${text('分享标题')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="shareTitle" maxlength="200" class="form-control"/>
							</div>
						</div>
					</div>
				</div>

				<div class="row">
					<div class="col-xs-12">
						<div class="form-group">
							<label class="control-label col-sm-2" title="">
								<span class="required hide">*</span> ${text('分享文案')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-10">
								<#form:textarea path="shareContent" rows="4" maxlength="200" class="form-control"/>
							</div>
						</div>
					</div>
				</div>

				<div class="row">
					<div class="col-xs-12">
						<div class="form-group">
							<label class="control-label col-sm-2" title="">
								<span class="required hide">*</span> ${text('分享图片')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-4">
								<#form:fileupload id="upload3" bizKey="1" bizType="1"
								uploadType="image" readonly="false" maxUploadNum="1" returnPath="true" filePathInputId="sharePic"/>
								<#form:hidden path="sharePic" name="sharePic" id="sharePic" />
							</div>

							<div>
								已上传图片：<img src="${wxActivity.sharePic}" width="80px" height="80px">
							</div>
						</div>
					</div>
				</div>



				<!--<div class="row">-->
					<!--<div class="col-xs-12">-->
						<!--<div class="form-group">-->
							<!--<label class="control-label col-sm-2" title="">-->
								<!--<span class="required hide">*</span> ${text('remarks')}：<i class="fa icon-question hide"></i></label>-->

							<!--<div class="col-sm-10">-->
								<!--<#form:textarea path="remarks" rows="4" maxlength="200" class="form-control"/>-->
							<!--</div>-->
						<!--</div>-->
					<!--</div>-->
				<!--</div>-->
				<div class="form-unit">${text('商家设置')}</div>
				<div class="row">
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4">分组选择：</label>
							<div class="col-sm-8">
								<#form:select path="businessGroupId"
								items="${wxActivity.wxBusinessGroupOrgConfigList}"
								itemLabel="groupName" itemValue="id" class="form-control required" id="groupSel" />
							</div>
						</div>
					</div>
				</div>


				<div class="form-unit">${text('H5活动链接')}</div>
				<div class="row" id="activityH5UrlDiv">
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required hide">*</span> ${text('H5活动海报链接')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="activityH5Url"  maxlength="300" class="form-control"  placeholder="保存后自动生成，无需填写" /> *将此链接复制到公众号菜单中
							</div>
						</div>
					</div>
				</div>

			</div>
			<div class="box-footer">
				<div class="row">
					<div class="col-sm-offset-2 col-sm-10">
						<% if (hasPermi('wx:wxActivity:edit')){ %>
							<button type="submit" class="btn btn-sm btn-primary" id="btnSubmit"><i class="fa fa-check"></i> ${text('保 存')}</button>&nbsp;
						<% } %>
						<button type="button" class="btn btn-sm btn-default" id="btnCancel" onclick="js.closeCurrentTabPage()"><i class="fa fa-reply-all"></i> ${text('关 闭')}</button>
					</div>
				</div>
			</div>
		</#form:form>
	</div>
</div>
<% } %>
<script src="//unpkg.com/wangeditor/release/wangEditor.min.js"></script>
<script>
$("#inputForm").validate({
	submitHandler: function(form){
		js.ajaxSubmitForm($(form), function(data){
			js.showMessage(data.message);
			if(data.result == Global.TRUE){
				js.closeCurrentTabPage(function(contentWindow){
					contentWindow.page();
				});
			}
		}, "json");
    }
});


// var p = {
//     // 标签参数
//     id: id!,					// 元素ID，如果不填写，则与name相同
//     path: path!,				// 绑定form上model中属性的值
//     name: name!,				// 元素名称，不填写
//     value: value!,				// 元素值
//
//     dictType: dictType!'',		// 字典类型，从字典里获取，自动设置items、itemLabel、itemValue
//
//     items: items!([]),			// 列表数据，可接受对象集合，如：List<DictData>
//     itemLabel: itemLabel!'',	// 指定列表数据中的什么属性名作为option的标签名
//     itemValue: itemValue!'',	// 指定列表数据中的什么属性名作为option的value值
//
//     label: label!,				// 只有一个复选按钮的情况下设置
//
// };

var theme = '${wxActivity.theme}'
if(theme){
    if(theme == '1'){
        $('#theme1').prop("checked",true)
    }else if(theme == '2'){
        $('#theme2').prop("checked",true)
    }else if(theme == '3'){
        $('#theme3').prop("checked",true)
    }else if(theme == '4'){
        $('#theme4').prop("checked",true)
	}else{
        $('#theme5').prop("checked",true)
    }
}

var editor;
var rule = $('#ruleText').val();

initEditor();
function initEditor(){
        var E = window.wangEditor
		editor = new E('#editor');
		editor.customConfig.onchange = function (html) {
			// 监控变化，同步更新到 textarea
			$('#ruleText').val(html);
			console.log(html)
		};
        // 自定义菜单配置
        editor.customConfig.menus = [
//	 		    'head',  // 标题
            'bold' /** 粗体*/, 'fontSize' /** 字号 */, 'fontName' /** 字体 */,'italic' /** 斜体 */,
//	 		    'underline',  // 下划线
//             'strikeThrough',  // 删除线
//             'foreColor',  // 文字颜色
//             'backColor',  // 背景颜色
//             'link',  // 插入链接
//             'list',  // 列表
            'justify',  // 对齐方式
            // 'quote',  // 引用
            // 'emoticon',  // 表情   打开后支持表情功能
            // 'image',  // 插入图片
            // 'table',  // 表格
            // 'video',  // 插入视频
//	 		    'code',  // 插入代码
            'undo',  // 撤销
            'redo'  // 重复
        ]

        editor.customConfig.uploadImgServer = 'pn/imagetextmaterial/localUpload'  // 上传图片到服务器
        // 将图片大小限制为 1M
        editor.customConfig.uploadImgMaxSize = 1 * 1024 * 1024
        editor.customConfig.uploadFileName = 'file';
        editor.customConfig.showLinkImg= false;
        // 限制一次最多上传 1 张图片
        editor.customConfig.uploadImgMaxLength = 1;
        editor.create();
    	editor.txt.html(rule)
}

$('#groupSel').change(function() {
	var groupId = $('#groupSel').val();
    console.log(groupId);

	//根据机构的分组id获取该分组下的商家

	$.ajax({
		url:'${ctx}/wx/wxBusiness/getBusinessByGroupId',
		data:{
            groupId:groupId
		},
		success:function (data) {

			$("#groupBusinessTreeDiv").attr("data-url",
				"${ctx}/wx/wxBusiness/getBusinessByGroupId?groupId="+groupId+"&other=")

			// console.log(data);
			// //动态绑定数据
			// var len = data.length;
			// var ht;
			// for(var i = 0 ;i < len ;i++){
			//     // ht = '<input name="Fruit" type="checkbox" class="form-control" value="'+data[i].id+'" />'+data[i].name+'';
			//     // ht += '<input name="Fruit" type="checkbox" class="form-control" value="'+data[i].id+'" />'+data[i].name+'';
			//
			//
			// 	ht ='<label>' +
			// 		'<div class="icheckbox_minimal-grey" aria-checked="false" aria-disabled="false" style="position: relative;">' +
			// 		'<input type="checkbox" id="mainwb'+(i+1)+'" name="businessApply" value="'+data[i].id+'" class="form-control" style="position: absolute; opacity: 0;">' +
			// 		'<ins class="iCheck-helper" style="position: absolute; top: 0%; left: 0%; display: block; width: 100%; height: 100%; margin: 0px; padding: 0px; background: rgb(255, 255, 255); border: 0px; opacity: 0;">' +
			// 		// '</ins>' +
			// 		'</div>'+data[i].name+'' +
			// 		'</label>';
			//
			// }
			// console.log(ht)
            // $("#mainwb").html("");
            // $("#mainwb").html(ht);
			//
            // var p = {
            //     // 标签参数
            //     id: 'mainwb!',					// 元素ID，如果不填写，则与name相同
            //     path: 'businessApply!',				// 绑定form上model中属性的值
            //     name: '1',				// 元素名称，不填写
            //     dictType: '1',		// 字典类型，从字典里获取，自动设置items、itemLabel、itemValue
            //     items: ([data]),			// 列表数据，可接受对象集合，如：List<DictData>
            //     itemLabel: 'name!',	// 指定列表数据中的什么属性名作为option的标签名
            //     itemValue: 'id!',	// 指定列表数据中的什么属性名作为option的value值
            //     label: '',				// 只有一个复选按钮的情况下设置
			//
            // };
            // // $("#mainwb").val(p);

        }

	})

});

</script>
